import config from "@/config/config.js";
import http from "@/api/http.js";


const detectItemRequest = {
    loadDetectItem(DetectName,page=1,limit=10,callBack){
        let token = localStorage.getItem("token");
        if(token){
            let url = config.defectBaseUrl + "/detectItem/list?page="+page + "&limit="+limit;
            if(DetectName){
                if (DetectName.templateId){
                    url += "&detectionId=" + DetectName.templateId;

                }
                if(DetectName.templateName){
                    url += "&detectionName=" + DetectName.templateName;
                }
                if (DetectName.templateType){
                    url += "&defectType=" + DetectName.templateType;
                }
            }
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },
    saveDetectItem(DetectName,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/detectItem/save";
            http.post(url,DetectName,callBack);
        }else {
            callBack(undefined);
        }
    },
    updateDetectItem(DetectName,callBack) {
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/detectItem/update";
            http.put(url,DetectName,callBack);
        } else {
            callBack(undefined);
        }
    },
    selectById(detectionId,callBack){
        let token = localStorage.getItem("token");
        if (token) {
            let url = config.defectBaseUrl + "/detectItem/get?detectionId=" + detectionId;
            http.get(url,callBack);
        }else {
            callBack(undefined);
        }
    },






}

export default detectItemRequest